<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>安帮基地信息编辑</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <style>
        .discell{
            text-align: right;
        }
        .input{
            width: 200px;
        }
    </style>
</head>
<body>
<form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
    <!-- 编辑框START-->
    <div id="editform" class="form mini-fit" style="margin:10px 0 40px;">
        <input name="id" id="id" value="${id!''}" class="mini-hidden" style="width: 100%;"/>
        <table class="form-table" align="center" cellspacing="8">
            <tr>
                <td class="discell"><font color="#dc143c">*</font>基地名称:</td>
                <td >
                    <input name="jdmc" id="jdmc" class="mini-textbox" style="width: 150px" required="true"/>
                </td>

                <td class="discell"><font color="#dc143c">*</font>基地性质:</td>
                <td>
                    <input name="jdxz"  id="jdxz" class="mini-combobox" style="width: 180px" required="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..."
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=3_6" onvaluechanged="changeField1(this)"
                    />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>基地邮编:</td>
                <td >
                    <input name="zipcode" id="zipcode" class="mini-textbox" style="width: 150px" required="true"
                           onvaluechanged="zipCodeChange()"/>
                </td>

                <td class="discell"><font color="#dc143c">*</font>救助类型:</td>
                <td>
                    <input name="jiuzhutype"  id="jiuzhutype" class="mini-combobox" style="width: 180px" required="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..."
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=3_7"
                    />
                </td>
            </tr>
            <tr>
                <td class="discell">
                    <font color="#dc143c">*</font>基地地址:
                </td>
                <td colspan="4" class="input">
                    <input  id = "province" name="province"  class="mini-combobox" required="true" emptyText = "省份" style="width:120px;"
                            textfield="codeName" valueField="codeId"
                            onclick="onDeptChanged('province')" onvaluechanged = "onValueChanged('province')"/>
                    <input  id = "city" name="city"  class="mini-combobox" required="true"  emptyText = "市" style="width: 120px"
                            textfield="codeName" valueField="codeId" onclick="onDeptChanged('city')"
                            onvaluechanged = "onValueChanged('city')"/>
                    <input  id = "county" name="county"  class="mini-combobox" required="true"  emptyText = "县" style="width: 122px"
                            textfield="codeName" valueField="codeId" onclick="onDeptChanged('county')"
                            onvaluechanged = "onValueChanged('county')"/>
                    <input  id = "village" name="village"  class="mini-combobox" required="true"  emptyText = "街道" style="width: 125px"
                            textfield="codeName" valueField="codeId"onclick="onDeptChanged('village')"/>
                </td>
            </tr>
            <tr>
                <td class="discell"></td>
                <td colspan="3">
                    <input class="mini-textbox" style="width: 498px" required="true" emptyText = "详细地址" id="dz" name="dz"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>帮扶范围:</td>
                <td colspan="2" class="input">
                    <input name="bffw" id="bffw" class="mini-combobox" style="width:200px;" required="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..." onvaluechanged="bffwInputClick()"
                           url="/azbj/bffw/getBffw?flog=${flog}"
                    />
                    <input id="bffwCode" name="bffwCode" class="mini-combobox" required="true" emptyText="下级地区编码" style="width:110px;"
                           textfield="codeName" valueField="codeId" onvaluechanged="checkBffwCode" multiSelect="true"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>基地成立时间:</td>
                <td class="input">
                    <input name="jstarttime" id="jstarttime" allowInput="false" class="mini-datepicker" required="true" ondrawdate="onDrawDate" emptyText = "基地成立时间"/>
                </td>
                <td colspan="discell"><font color="#dc143c">*</font>可安置人员数量:</td>
                <td class="input" colspan="3">
                    <input id="keAnzhirenshu" name="keAnzhirenshu" class="mini-spinner"  minValue="1" value="1" style="width: 180px" required="true"/>人</td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>有效时间:</td>
                <td class="input" colspan="3">
                    <input name="firmlyTime"  id="firmlyTime" allowInput="false" class="mini-datepicker" required="true" emptyText = "开始时间" />至<input name="deadTime"  id="deadTime" allowInput="false" class="mini-datepicker" required="true" ondrawdate="onDrawDate1" emptyText = "结束时间"/>
                </td>
            </tr>
            <tr>
                <td class="discell">安置刑满释放人员数量:</td>
                <td >
                    <input name="anzhirenshu" id="anzhirenshu" class="mini-spinner" minValue="0" maxValue="200000" style="width: 150px" emptyText="可滚动鼠标滚轮调整"/>人
                </td>

                <td class="discell">历史安置总人次:</td>
                <td >
                    <input name="lsAnzhirenshu" id="lsAnzhirenshu" class="mini-spinner" minValue="0" maxValue="200000"  style="width: 180px" emptyText="可滚动鼠标滚轮调整"/>人
                </td>
            </tr>
            <#if "${localCode!''}" == "140000">
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>基地法人:</td>
                    <td >
                        <input id="corporation" name="corporation" class="mini-textbox" style="width: 150px" required="true"/>
                    </td>

                    <td class="discell"><font color="#dc143c">*</font>基地联系方式:</td>
                    <td >
                        <input id="corporationPhone" name="corporationPhone" class="mini-textbox"  style="width: 180px" required="true" onvaluechanged="checkPhone(3)"/>
                    </td>
                </tr>
            </#if>
            <tr>
                <td rowspan="2" class="discell"><font color="#dc143c">*</font>联系人:</td>
                <td rowspan="2">
                    <input name="fr" class="mini-textbox"  style="width: 150px" required="true"/>
                </td>

                <td class="discell">基地联系人手机号码:</td>
                <td >
                    <input id="phone" name="dh" class="mini-textbox" style="width: 180px" onvaluechanged="checkPhone(1)" emptyText="请输入手机号码" />
                </td>
            </tr>
            <tr>
                <td class="discell">基地联系人固话:</td>
                <td >
                    <input id="tel" name="tel" class="mini-textbox" style="width: 180px" onvaluechanged="checkPhone(2)" emptyText="请输入固定电话" />
                </td>
            </tr>
            <tr>
                <td class="discell">基地建筑面积:</td>
                <td >
                    <input id = "jianzhumianji" name="jianzhumianji" class="mini-spinner" minValue="0" maxValue="200000" style="width: 150px" emptyText="可滚动鼠标滚轮调整"/>平方米
                </td>

                <td class="discell">基地房间数:</td>
                <td >
                    <input id = "fangjianshu" name="fangjianshu" class="mini-spinner" minValue="0" maxValue="200000" style="width: 180px" emptyText="可滚动鼠标滚轮调整"/>间
                </td>
            </tr>
            <#if "${localCode!''}" == "140000">
                <tr>
                    <td class="discell" id="jxpxkm">生产经营项目:</td>
                    <td colspan="3">
                        <input class="mini-textarea" style="width: 498px" emptyText="请输入生产经营项目" id="jpeixun" name="jpeixun" />
                    </td>
                </tr>
            <#else>
                <tr>
                    <td class="discell">教育培训科目:</td>
                    <td colspan="3">
                        <input class="mini-textarea" style="width: 498px" emptyText="请输入教育培训科目" id="jpeixun" name="jpeixun" />
                    </td>
                </tr>
            </#if>
        </table>
        <#if "${localCode!''}" == "140000">
            <!-- 上传基地认证证明-->
            <div id="fileform" class="form" style="padding-left:200px;">
                <table class="form-table" align="center" width="100%">
                    <tr>
                        <td colspan="2">
                            <div class="legend">附件上传</div>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-left: 80px;">
                            <input style="background: #4A89FD;color: #fff;outline: none;border: none;height: 25px;" type="button" value="上传基地认证证明材料" onclick="onFileUpload()"><span  style="color: #8B8B8B" > 支持扩展名：.rar .zip .doc .docx .pdf .jpg...</span>
                        </td>
                        <td style="color: #8B8B8B;font-size:8px;">

                        </td>
                    </tr>
                </table>
            </div>
            <!--上传基地照片-->
            <div id="fileform" class="form" style="padding-left:200px">
                <table class="form-table" align="center" width="100%">
                    <tr>
                        <td colspan="2">
                            <div class="legend">照片上传</div>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-left: 80px;">
                            <input style="background: #4A89FD;color: #fff;outline: none;border: none;height: 25px;" type="button" value="基地照片上传" onclick="onPhotoUpload()"><span  style="color: #8B8B8B" > 支持扩展名：pdf .jpg...</span>
                        </td>
                        <td style="color: #8B8B8B;font-size:8px;">

                        </td>
                    </tr>
                </table>
            </div>
        </#if>
    </div>
    <!--编辑框END-->
    <div style="position: absolute;bottom: 0;line-height: 40px;width: 100%;border-top:1px solid #dfdfdf;text-align: center">
        <#if flog!='1'>
            <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()" >保存</a>
        </#if>
        <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()" >关闭</a>
    </div>
</form>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var province = mini.get("province");
    var id = mini.get("id");
    var city = mini.get("city");
    var county = mini.get("county");
    var village = mini.get("village");
    var zzdz = mini.get("zzdz");
    var zipcode = mini.get("zipcode");
    var corphone = mini.get("corporationPhone");
    var bffw = mini.get('bffw');
    var bffwCode = mini.get('bffwCode');
    var bffwCodeData = [{codeId: '-1', codeName: '全区域'}];

    $(document).ready(function () {
        if(bffw.getData()[0].codeId==4){
            $('#bffwCode').hide();
        }
        mini.get("lsAnzhirenshu").setEnabled(false);
        mini.get("anzhirenshu").setEnabled(false);
        addressLocking();
    });

    //地址锁定
    function addressLocking(){
        $.ajax({
            url: "/azbj/getAddressLocking",
            type: "GET",
            success: function (res) {
                if(res.level == "06" || res.level == "07" || res.level == "08" || res.level == "03"){
                    province.setData([{"codeId": res.shengCode, "codeName": res.shengName}]);
                    province.setValue(res.shengCode);
                    province.setEnabled(false);
                }
                if(res.level == "07" || res.level == "08" || res.level == "03"){
                    city.setData([{"codeId": res.dishiCode, "codeName": res.dishiName}]);
                    city.setValue(res.dishiCode);
                    city.setEnabled(false);
                }
                if(res.level == "08" || res.level == "03"){
                    county.setData([{"codeId": res.quxianCode, "codeName": res.quxianName}]);
                    county.setValue(res.quxianCode);
                    county.setEnabled(false);
                }
                if(res.level == "03"){
                    village.setData([{"codeId": res.jiedaoCode, "codeName": res.jiedaoName}]);
                    village.setValue(res.jiedaoCode);
                    village.setEnabled(false);
                }
            }
        });
    }

    //标准方法接口定义
    function SetData(data) {
        if(${flog!''}!=1 && !check(data.anzhirenshu)){
            mini.alert("您之前录入的安置刑满释放人员数量为:【"+data.anzhirenshu+"】,不是数字,请重新设置并保存！");
        }
        if(${flog!''}!=1 && !check(data.lsAnzhirenshu)){
            mini.alert("您之前录入的历史安置总人次为:【"+data.lsAnzhirenshu+"】,不是数字,请重新设置并保存！");
        }
        if(${flog!''}!=1 && !check(data.jianzhumianji)){
            mini.alert("您之前录入的基地建筑面积为:【"+data.jianzhumianji+"】,不是数字,请重新设置并保存！");
        }
        if(${flog!''}!=1 && !check(data.fangjianshu)){
            mini.alert("您之前录入的基地房间数为:【"+data.fangjianshu+"】,不是数字,请重新设置并保存！");
        }
        if (data.zzmc) {
            mini.get("zzmc").setEnabled(false);
        }
        var o = mini.decode(data);
        document.getElementById("keAnzhirenshu").value = o.keAnzhirenshu;
        document.getElementById("jianzhumianji").value = o.jianzhumianji;
        document.getElementById("fangjianshu").value = o.fangjianshu;
        form.setData(o);
        form.setChanged(false);
        if (${flog!''}==1)
        {
            form.setEnabled(false);
        }
        if(!o.id) {
            id.setValue(${id!''});
        }
        if(mini.get('jdmc').getValue()!='' && mini.get('jdmc').getValue()!=undefined ){
            setBffwCode(bffwCode.getValue());
        }
        //设置省市县回显
        province.setData([{"codeId":data.province,"codeName":data.provinceName}]);
        city.setData([{"codeId":data.city,"codeName":data.cityName}]);
        county.setData([{"codeId":data.county,"codeName":data.countyName}]);
        village.setData([{"codeId":data.village,"codeName":data.villageName}]);
    }

    //帮扶范围点击
    function bffwInputClick(){
        if(province.getValue()=='' || city.getValue()=='' || county.getValue()=='' || village.getValue()==''){
            mini.alert('请填写机构地址信息');
            bffw.setValue(null);
        }else {
            setBffwCode(bffwCode.getValue());
        }
    }

    function setBffwCode(bffwCodeId){
        bffwCodeData = [{codeId: '-1', codeName: '全区域'}];
        if(bffw.getValue()==1){
            bffwCode.setText('下级地市');
            if(city.getData().length==0){
                onDeptChanged('city')
            }
            bffwCodeData = bffwCodeData.concat(city.getData())
            $('#bffwCode').show();
        }else if(bffw.getValue()==2){
            bffwCode.setText('下级区县');
            if(county.getData().length==0){
                onDeptChanged('county')
            }
            bffwCodeData = bffwCodeData.concat(county.getData())
            $('#bffwCode').show();
        }else if(bffw.getValue()==3) {
            bffwCode.setText('下级街道');
            if(village.getData().length==0){
                onDeptChanged('village')
            }
            bffwCodeData = bffwCodeData.concat(village.getData())
            $('#bffwCode').show();
        }else {
            $('#bffwCode').hide();
        }
        bffwCode.setData(bffwCodeData);
        if(bffwCodeId=='' || bffwCodeId==undefined || bffwCodeId=='无'){
            bffwCode.setValue('-1');
        }
    }

    //检查是否包含-1
    function checkBffwCode(){
        if(bffwCode.getValue().indexOf('-1')!==-1){
            bffwCode.setValue('-1');
        }
    }

    //校验数字(带小数点)
    function check(e) {
        var re = /^[1-9][0-9]*([.][0-9]{1,2})?$/;
        if (e != "" && e!=undefined && e!=0) {
            if (!re.test(e)) {
                return false;
            }
            return true;
        }
        return true;
    }



    function saveData() {
        //验证非空字段
        form.validate();
        if (form.isValid() == false || ${flog!''} == 1) {
            return;
        }
        var data = form.getData();
        data.flag = ${flag};
        //有效时间开始 大于 结束
        if(data.firmlyTime > data.deadTime){
            mini.alert("有效期开始不能大于结束");
            return;
        }
        //基地成立时间 大于 有效时间开始
        if(data.jstarttime > data.firmlyTime){
            mini.alert("基地成立时间不能大于有效期开始时间");
            return;
        }
        var tel = data.tel;
        var phone = data.dh;
        //手机号码和固定电话必须有一个要填
        var newPhone = checkTelAndPhone(tel,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if('-1'===kflag){
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if(flag){
            data.dh = newPhone['newTelAndPhone'];
        }else{
            mini.alert("联系电话或手机号有误，请重填");
            return;
        }
        var zipFlag = zipCodeChange(data.zipcode);
        if(!zipFlag){
            return;
        }
        if(${localCode!''} == "140000") {
            if(!checkPhone("3")){
                return;
            }
        }
        var json = mini.encode(data);
        commonSaveData("/azbj/jdxxgl/placementBaseInfo/save", {data: json}, callback);
        // 保存成功的回调函数
        function callback() {
            mini.alert("保存成功","成功",window.CloseOwnerWindow);
        }
    }

    /**
     * 住址
     * @param e
     */
    var urltemp = "/azbj/getCodeDetail/?codeType=2_1&codeId=-2";
    function onDeptChanged(e) {
        if("province" == e){
            var value = province.getValue();
            province.setValue("");
            var url =  "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            province.setUrl(url);
            if(value!=''){
                province.setValue(value);
            } else {
                province.select(0);
            }
        }
        if("city" == e){
            var value = city.getValue();

            if(province.getValue()==""){
                province.setUrl(urltemp);
                province.setValue("");
                county.setUrl(urltemp);
                county.setValue("");
                village.setUrl(urltemp);
                village.setValue("");
                return;
            }
            var codeId = province.getValue();
            city.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            city.setUrl(url);
            if(value!=''){
                city.setValue(value);
            } else {
                city.select(0);
            }
        }
        if("county" == e) {
            var value = county.getValue();

            if(city.getValue()==""){
                county.setUrl(urltemp);
                county.setValue("");
                village.setUrl(urltemp);
                village.setValue("");
                return;
            }
            var codeId = city.getValue();
            county.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            county.setUrl(url);
            if(value!=''){
                county.setValue(value);
            } else {
                county.select(0);
            }
        }
        if("village" == e){
            var value = village.getValue();

            if(county.getValue()==""){
                village.setUrl(urltemp);
                village.setValue("");
                return;
            }
            var parent_code = county.getValue();
            village.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            village.setUrl(url);
            if(value!=''){
                village.setValue(value);
            } else {
                village.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if("province" == e){
            city.setValue("");
            county.setValue("");
            village.setValue("");
        }
        if("city" == e){
            county.setValue("");
            village.setValue("");
        }
        if("county" == e) {
            village.setValue("");
        }
    }

    //电话号码的验证
    function checkPhone(e){
        var phone = mini.get("phone").getValue();
        var tel = mini.get("tel").getValue();
        var tel = mini.get("tel").getValue();
        if(${localCode!''} == "140000") {
            var corphone = mini.get("corporationPhone").getValue();
        }
        if("1"==e){
            if(phone != '' && !(/^1[3456789]\d{9}$/.test(phone))){
                mini.alert("手机号码有误，请重填");
                return false;
            }
        } else if("2"==e){
            if(tel != '' && !/^((0\d{2,3})-?)(\d{7,8})$/.test(tel)){
                mini.alert('固定电话有误，请重填');
                return false;
            }
        } else if("3"==e){
            if(corphone == ''){
                mini.alert("请至少输入一个法人联系方式");
                return false;
            }else if(corphone != '' && (/^((0\d{2,3})-?)(\d{7,8})$/.test(corphone) || /^1[3456789]\d{9}$/.test(corphone))){
                return true;
            }else{
                mini.alert('法人联系方式有误，请重填');
                return false;
            }
        }
        if(phone == '' && tel == ''){
            mini.alert("请至少输入一个联系方式");
            return false;
        }
    }

    // 邮编校验
    function zipCodeChange(){
        // 例如,北京100000
        var zipcode = mini.get("zipcode").getValue();
        if(zipcode != '' && !(/^[0-9]\d{5}$/).test(zipcode)) {
            mini.alert("基地邮编有误,请重填!");
            return false;
        }
        return true;
    }

    //成立时间不能选择比今天靠后的日期
    function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        //选择的日期大于今天日期 不能选
        if (date.getTime() > d.getTime()) {
            e.allowSelect = false;
        }
    }

    /**
     * 禁止选择今天之前的日期
     * @param e
     */
    function onDrawDate1(e) {
        var date = e.date;
        var d = new Date();
        //一天等于86400000ms
        if (d.getTime()-86400000 > date.getTime()) {
            e.allowSelect = false;
        }
    }

    // 上传证明材料 taskId=33 33安帮基地信息 证明材料
    function onFileUpload() {
        var id = mini.get("id").getValue();
        if(!id){
            id=${id!''};
        }
        commonEdit("/upload/user/uploadAppendixfile/view?1=1&id="+id+"&priNum="+id+"&taskId=33", "上传文件", null, "40%", "40%",true,true,true, null);
    }

    // 上传证明材料 taskId=34 34安帮基地照片
    function onPhotoUpload() {
        var id = mini.get("id").getValue();
        if(!id){
            id=${id!''};
        }
        commonEdit("/upload/user/uploadAppendixfile/view?1=1&id="+id+"&priNum="+id+"&taskId=34", "上传文件", null, "40%", "40%",true,true,true, null);
    }

    window.onload = function () {
        id.setValue(${id!''});
    }

    function changeField1(e) {
        if(e.value=='1'){
            document.getElementById("jxpxkm").innerHTML="生产经营项目:";
        } else {
            document.getElementById("jxpxkm").innerHTML="教育培训科目:";
        }
    }
</script>
</body>
</html>